package logic

import (
	"context"

	"storage/internal/svc"
	"storage/pb/storage"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetFileByIDsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetFileByIDsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileByIDsLogic {
	return &GetFileByIDsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// GetFileByIDs 获取文件列表
func (l *GetFileByIDsLogic) GetFileByIDs(in *storage.IDListRequest) (*storage.FileListResponse, error) {
	files, err := l.svcCtx.StorageModel.GetFilesByIDs(l.ctx, in.Ids)
	if err != nil {
		return nil, err
	}

	var fileList []*storage.FileInfo
	for _, file := range files {
		fileList = append(fileList, &storage.FileInfo{
			Id:       file.Id,
			UserId:   file.UserId,
			ParentId: file.ParentId,
			FileName: file.FileName,
			FileHash: file.FileHash,
			FileSize: file.FileSize,
			FileType: file.FileType,
			Status:   file.Status,
			CreateAt: file.CreateAt.Unix(),
			UpdateAt: file.UpdateAt.Unix(),
		})
	}
	return &storage.FileListResponse{List: fileList}, nil
}
